import { IParam, IContext, DataServiceBase, IHttpResponse } from '@/core';
import {
	Auth_loginCommonDTOHelp,
	Auth_loginDTOHelp,
	Auth_loginRequestDTOHelp,
	Auth_loginResponseDTOHelp,
	Auth_logincaptchaDTOHelp,
	Auth_loginchangePwdDTOHelp,
} from '../dto-help/auth-helps';
import { Auth } from '../auth';
import AuthKeys from '../auth-keys';

/**
 * 登录信息服务对象基类
 * 基于template/src/api/{{appEntities}}/data-service/{{appEntities}}-service-base.ts.hbs生成
 *
 * @export
 * @class Auth
 * @extends {EntityBaseService}
 */
export class AuthServiceBase extends DataServiceBase<Auth> {
	/**
	 * 存储模式
	 *
	 * @type {(0 | 1 | 3 | 4)} 无本地存储 | 仅本地存储 | 本地及远程存储 | DTO无存储
	 * @memberof AuthServiceBase
	 */
	readonly storageMode: number = 0;

	/**
	 * Creates an instance of AuthServiceBase.
	 *
	 * @param {*} [opts={}]
	 * @memberof AuthServiceBase
	 */
	constructor(opts: IParam = {}) {
		super(opts, 'Auth');
	}

	/**
	 * 初始化基础数据
	 *
	 * @protected
	 * @memberof AuthServiceBase
	 */
	protected initBasicData() {
		this.systemName = 'uaa';
		this.appName = 'web';
		this.appEntityName = 'auth_login';
		this.appEntityCodeName = 'auth';
		this.appEntityCodeNames = 'auths';
		this.appEntityKeyCodeName = 'id';
		this.appEntityTextCodeName = 'login_name';
	}

	/**
	 * 构造实体
	 *
	 * @protected
	 * @param {IParam} data
	 * @param {IContext} [context]
	 * @return {*} { Auth }
	 * @memberof AuthServiceBase
	 */
	protected newEntity(data: IParam, context: IContext = {}): Auth {
		return new Auth(data);
	}

	/**
	 * 过滤当前实体服务，标准接口数据
	 *
	 * @return {*}  {*}
	 * @memberof AuthServiceBase
	 */
	protected filterEntityData(entity: Auth): any {
		const data: any = {};
		AuthKeys.forEach((key) => {
			if (entity[key] !== void 0) {
				data[key] = entity[key];
			}
		});
		return data;
	}

	/**
	 * Bind
	 *
	 * @param {IParam} [context={}]
	 * @param {IParam | IParam[]} [data]
	 * @returns {Promise<any>}
	 * @memberof AuthServiceBase
	 */
	public async Bind(
		context: IContext = {},
		data: IParam | IParam[]
	): Promise<any> {
		data = data ? data : {};
		let requestPath = '';
		requestPath = `/auths/bind`;
		data = await Auth_loginCommonDTOHelp.get(context, data);
		const res = await this.http.post(requestPath, data);
		res.data = await Auth_loginResponseDTOHelp.set(context, res.data);
		return res;
	}

	/**
	 * Cache_evict
	 *
	 * @param {IParam} [context={}]
	 * @param {IParam | IParam[]} [data]
	 * @returns {Promise<any>}
	 * @memberof AuthServiceBase
	 */
	public async Cache_evict(
		context: IContext = {},
		data: IParam | IParam[]
	): Promise<any> {
		data = data ? data : {};
		let requestPath = '';
		requestPath = `/auths/cache_evict`;
		data = await Auth_loginDTOHelp.get(context, data);
		const res = await this.http.post(requestPath, data);
		res.data = await Auth_loginDTOHelp.set(context, res.data);
		return res;
	}

	/**
	 * Captcha
	 *
	 * @param {IParam} [context={}]
	 * @param {IParam | IParam[]} [data]
	 * @returns {Promise<any>}
	 * @memberof AuthServiceBase
	 */
	public async Captcha(
		context: IContext = {},
		data: IParam | IParam[]
	): Promise<any> {
		data = data ? data : {};
		let requestPath = '';
		requestPath = `/auths/captcha`;
		data = await Auth_loginCommonDTOHelp.get(context, data);
		const res = await this.http.post(requestPath, data);
		res.data = await Auth_logincaptchaDTOHelp.set(context, res.data);
		return res;
	}

	/**
	 * Login
	 *
	 * @param {IParam} [context={}]
	 * @param {IParam | IParam[]} [data]
	 * @returns {Promise<any>}
	 * @memberof AuthServiceBase
	 */
	public async Login(
		context: IContext = {},
		data: IParam | IParam[]
	): Promise<any> {
		data = data ? data : {};
		let requestPath = '';
		requestPath = `/auths/login`;
		data = await Auth_loginRequestDTOHelp.get(context, data);
		const res = await this.http.post(requestPath, data);
		res.data = await Auth_loginResponseDTOHelp.set(context, res.data);
		return res;
	}

	/**
	 * LoginByCode
	 *
	 * @param {IParam} [context={}]
	 * @param {IParam | IParam[]} [data]
	 * @returns {Promise<any>}
	 * @memberof AuthServiceBase
	 */
	public async LoginByCode(
		context: IContext = {},
		data: IParam | IParam[]
	): Promise<any> {
		data = data ? data : {};
		let requestPath = '';
		requestPath = `/auths/loginbycode`;
		data = await Auth_loginCommonDTOHelp.get(context, data);
		const res = await this.http.post(requestPath, data);
		res.data = await Auth_loginResponseDTOHelp.set(context, res.data);
		return res;
	}

	/**
	 * LoginBySmsCode
	 *
	 * @param {IParam} [context={}]
	 * @param {IParam | IParam[]} [data]
	 * @returns {Promise<any>}
	 * @memberof AuthServiceBase
	 */
	public async LoginBySmsCode(
		context: IContext = {},
		data: IParam | IParam[]
	): Promise<any> {
		data = data ? data : {};
		let requestPath = '';
		requestPath = `/auths/loginbysmscode`;
		data = await Auth_loginCommonDTOHelp.get(context, data);
		const res = await this.http.post(requestPath, data);
		res.data = await Auth_loginResponseDTOHelp.set(context, res.data);
		return res;
	}

	/**
	 * Logout
	 *
	 * @param {IParam} [context={}]
	 * @param {IParam | IParam[]} [data]
	 * @returns {Promise<any>}
	 * @memberof AuthServiceBase
	 */
	public async Logout(
		context: IContext = {},
		data: IParam | IParam[]
	): Promise<any> {
		data = data ? data : {};
		let requestPath = '';
		requestPath = `/auths/${encodeURIComponent(context['auth'])}/logout`;
		const res = await this.http.get(requestPath, data);
		res.data = await Auth_loginDTOHelp.set(context, res.data);
		return res;
	}

	/**
	 * Rebind
	 *
	 * @param {IParam} [context={}]
	 * @param {IParam | IParam[]} [data]
	 * @returns {Promise<any>}
	 * @memberof AuthServiceBase
	 */
	public async Rebind(
		context: IContext = {},
		data: IParam | IParam[]
	): Promise<any> {
		data = data ? data : {};
		let requestPath = '';
		requestPath = `/auths/rebind`;
		data = await Auth_loginDTOHelp.get(context, data);
		const res = await this.http.post(requestPath, data);
		res.data = await Auth_loginDTOHelp.set(context, res.data);
		return res;
	}

	/**
	 * Refresh_token
	 *
	 * @param {IParam} [context={}]
	 * @param {IParam | IParam[]} [data]
	 * @returns {Promise<any>}
	 * @memberof AuthServiceBase
	 */
	public async Refresh_token(
		context: IContext = {},
		data: IParam | IParam[]
	): Promise<any> {
		data = data ? data : {};
		let requestPath = '';
		requestPath = `/auths/${encodeURIComponent(context['auth'])}/refresh_token`;
		const res = await this.http.get(requestPath, data);
		res.data = await Auth_loginResponseDTOHelp.set(context, res.data);
		return res;
	}

	/**
	 * Register
	 *
	 * @param {IParam} [context={}]
	 * @param {IParam | IParam[]} [data]
	 * @returns {Promise<any>}
	 * @memberof AuthServiceBase
	 */
	public async Register(
		context: IContext = {},
		data: IParam | IParam[]
	): Promise<any> {
		data = data ? data : {};
		let requestPath = '';
		requestPath = `/auths/register`;
		data = await Auth_loginCommonDTOHelp.get(context, data);
		const res = await this.http.post(requestPath, data);
		res.data = await Auth_loginResponseDTOHelp.set(context, res.data);
		return res;
	}

	/**
	 * SendSMSCode
	 *
	 * @param {IParam} [context={}]
	 * @param {IParam | IParam[]} [data]
	 * @returns {Promise<any>}
	 * @memberof AuthServiceBase
	 */
	public async SendSMSCode(
		context: IContext = {},
		data: IParam | IParam[]
	): Promise<any> {
		data = data ? data : {};
		let requestPath = '';
		requestPath = `/auths/sendsmscode`;
		data = await Auth_loginCommonDTOHelp.get(context, data);
		const res = await this.http.post(requestPath, data);
		res.data = await Auth_loginResponseDTOHelp.set(context, res.data);
		return res;
	}

	/**
	 * SocialRegister
	 *
	 * @param {IParam} [context={}]
	 * @param {IParam | IParam[]} [data]
	 * @returns {Promise<any>}
	 * @memberof AuthServiceBase
	 */
	public async SocialRegister(
		context: IContext = {},
		data: IParam | IParam[]
	): Promise<any> {
		data = data ? data : {};
		let requestPath = '';
		requestPath = `/auths/socialregister`;
		data = await Auth_loginCommonDTOHelp.get(context, data);
		const res = await this.http.post(requestPath, data);
		res.data = await Auth_loginResponseDTOHelp.set(context, res.data);
		return res;
	}

	/**
	 * Unlock
	 *
	 * @param {IParam} [context={}]
	 * @param {IParam | IParam[]} [data]
	 * @returns {Promise<any>}
	 * @memberof AuthServiceBase
	 */
	public async Unlock(
		context: IContext = {},
		data: IParam | IParam[]
	): Promise<any> {
		data = data ? data : {};
		let requestPath = '';
		requestPath = `/auths/${encodeURIComponent(context['auth'])}/unlock`;
		const res = await this.http.get(requestPath, data);
		res.data = await Auth_loginDTOHelp.set(context, res.data);
		return res;
	}

	/**
	 * change_pwd
	 *
	 * @param {IParam} [context={}]
	 * @param {IParam | IParam[]} [data]
	 * @returns {Promise<any>}
	 * @memberof AuthServiceBase
	 */
	public async change_pwd(
		context: IContext = {},
		data: IParam | IParam[]
	): Promise<any> {
		data = data ? data : {};
		let requestPath = '';
		requestPath = `/auths/change_pwd`;
		data = await Auth_loginchangePwdDTOHelp.get(context, data);
		const res = await this.http.post(requestPath, data);
		res.data = await Auth_loginResponseDTOHelp.set(context, res.data);
		return res;
	}
}
